/**
 * Created by lxy_920912 on 27/03/2017.
 */
var permute = function(nums) {
    var list = [];
    backTrace(nums,0,nums.length);
    return list;

    function backTrace(nums,start,end) {
        if(start >= end){
            list.push([].concat(nums));
            return;
        }
        if(start < end){
            for(var i = start;i < end;i++){
                swap(nums,start,i);
                backTrace(nums,start+1,end);
                swap(nums,start,i);
            }
        }
    }
    function swap(nums,i,j) {
        var temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
};
